{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "a9c8dc94",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Text converted and saved as 'output.xlsx'\n"
     ]
    }
   ],
   "source": [
    "import openpyxl\n",
    "\n",
    "def convert_text_to_sheets(text_file, excel_file):\n",
    "    # Create a new workbook\n",
    "    workbook = openpyxl.Workbook()\n",
    "\n",
    "    # Read the text file\n",
    "    with open(text_file, 'r') as file:\n",
    "        lines = file.readlines()\n",
    "\n",
    "    # Create a new sheet\n",
    "    sheet = workbook.active\n",
    "\n",
    "    # Populate the sheet with lines of text\n",
    "    for i, line in enumerate(lines):\n",
    "        # Split the line by spaces\n",
    "        words = line.strip().split()\n",
    "\n",
    "        # Copy words to respective cells in the row\n",
    "        for j, word in enumerate(words):\n",
    "            cell = sheet.cell(row=i+1, column=j+1)\n",
    "            cell.value = word\n",
    "\n",
    "    # Save the Excel file\n",
    "    workbook.save(excel_file)\n",
    "\n",
    "    print(f\"Text converted and saved as '{excel_file}'\")\n",
    "\n",
    "# Specify the input text file and output Excel file paths\n",
    "text_file_path = 'input.txt'\n",
    "excel_file_path = 'output.xlsx'\n",
    "\n",
    "# Convert text to sheets in Excel\n",
    "convert_text_to_sheets(text_file_path, excel_file_path)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7208a1fc",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
